﻿<%@ Page Title="Transactions" Language="C#" MasterPageFile="~/Backoffice/BackOffice.Master"
    AutoEventWireup="true" CodeBehind="Transactions.aspx.cs" Inherits="TreaShares.Backoffice.User.Transactions" %>

<%@ MasterType VirtualPath="~/Backoffice/BackOffice.Master" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolderHead" runat="server">
    <script type="text/javascript" src="/scripts/jquery.cookie.js"></script>
    <script type="text/javascript">
        $(function () {

            var dates = $("#txtSummaryFrom, #txtSummaryTo").datepicker({
                defaultDate: "+1d",
                changeMonth: true,
                //numberOfMonths: 3,
                showOn: 'button',
                buttonImage: '/images/Icons/calendar.gif',
                buttonImageOnly: true,
                onSelect: function (selectedDate) {
                    var option = this.id == "txtSummaryFrom" ? "minDate" : "maxDate",
					instance = $(this).data("datepicker"),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings);
                    dates.not(this).datepicker("option", option, date);
                }
            });
            $("#tabs").tabs({
                cookie: { expires: 1 }
                //,selected: defaultReportingJS,
            });
            if ($("#txtSummaryTo").val() == "" && $("#txtSummaryFrom").val() == "") {
                var today = new Date();
                var startOfTheYear = new Date(today.getFullYear(), 0, 1, 0, 0, 0, 0);
                $("#txtSummaryTo").datepicker('setDate', today);
                $("#txtSummaryFrom").datepicker('setDate', startOfTheYear);
            }
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">Transactions Listing</a></li>
            <li><a href="#tabs-2">Stock Summary</a></li>
        </ul>
        <div id="tabs-1">
            <div class="RadioButtonList" align="right" style="padding-bottom: 5px">
                <asp:Button ID="Button3" CssClass="button" Width="150px" Text="Export to CSV" OnClick="Button3_Click"
                    runat="server"></asp:Button>
                <asp:Button ID="Button1" CssClass="button" Width="150px" Text="Export to PDF" OnClick="Button4_Click"
                    runat="server"></asp:Button>
            </div>
            <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"
               AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="false"  GridLines="None"
                ShowGroupPanel="True" ShowFooter="true" AllowAutomaticDeletes="true" DataSourceID="ObjectDataSource1" OnItemCommand="RadGrid1_ItemCommand"
                HeaderStyle-HorizontalAlign="Center">
                <ClientSettings AllowDragToGroup="True" ReorderColumnsOnClient="True">
                    <Selecting AllowRowSelect="True" />
                </ClientSettings>
                <FilterItemStyle Width="50px" />
                <ExportSettings IgnorePaging="true" OpenInNewWindow="true" FileName="Transactions"
                    ExportOnlyData="true">
                    <Pdf PageTitle="Transactions" PageWidth="297mm" PageHeight="210mm" FontType="Subset"
                        Producer="Treashares.com" AllowPrinting="true" />
                </ExportSettings>
                <GroupingSettings RetainGroupFootersVisibility="true" ShowUnGroupButton="true" />
                <MasterTableView DataSourceID="ObjectDataSource1" DataKeyNames="Id" ShowGroupFooter="true"
                    CommandItemDisplay="Top">
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridNumericColumn DataField="Id" HeaderText="Trade ID" HeaderStyle-Width="50px"
                            FilterControlWidth="40px" ShowFilterIcon="false" />
                        <telerik:GridDateTimeColumn DataField="TransactionDate" HeaderText="Trade Date" DataFormatString="{0:d}"
                            FilterControlWidth="80px" ShowFilterIcon="true" PickerType="DatePicker" HeaderStyle-Width="120px">
                        </telerik:GridDateTimeColumn>
                        <telerik:GridDateTimeColumn DataField="ValueDate" UniqueName="ValueDate" HeaderText="Value Date"
                            DataFormatString="{0:d}" FilterControlWidth="80px" ShowFilterIcon="true" PickerType="DatePicker"
                            HeaderStyle-Width="120px">
                        </telerik:GridDateTimeColumn>
                        <telerik:GridDateTimeColumn DataField="VestingDate" HeaderText="Vesting Date" DataFormatString="{0:d}"
                            FilterControlWidth="80px" ShowFilterIcon="true" PickerType="DatePicker" HeaderStyle-Width="120px">
                        </telerik:GridDateTimeColumn>
                        <telerik:GridBoundColumn DataField="EntityName" HeaderText="Entity" HeaderStyle-Width="40px"
                            FilterControlWidth="40px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TransactionType" HeaderText="Type" HeaderStyle-Width="40px"
                            FilterControlWidth="40px">
                            <FilterTemplate>
                                <telerik:RadComboBox ID="cbTransactionType" runat="server" OnClientSelectedIndexChanged="TransactionTypeSelectedIndexChanged"
                                    SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("TransactionType").CurrentFilterValue %>'
                                    Width="70px">
                                    <Items>
                                        <telerik:RadComboBoxItem Text="NoFilter" Value="" />
                                        <telerik:RadComboBoxItem Text="Stock" Value="Stock" />
                                        <telerik:RadComboBoxItem Text="Option" Value="Option" />
                                    </Items>
                                </telerik:RadComboBox>
                                <telerik:RadScriptBlock ID="RadScriptBlock13" runat="server">
                                    <script type="text/javascript">
                                        function TransactionTypeSelectedIndexChanged(sender, args) {
                                            var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                            var filterVal = args.get_item().get_value();
                                            if (filterVal == "") {
                                                tableView.filter("TransactionType", filterVal, "NoFilter");
                                            }
                                            else if (filterVal == "Stock") {
                                                tableView.filter("TransactionType", "Stock", "EqualTo");
                                            }
                                            else if (filterVal == "Option") {
                                                tableView.filter("TransactionType", "Option", "EqualTo");
                                            }
                                        } 
                                    </script>
                                </telerik:RadScriptBlock>
                            </FilterTemplate>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="CounterPartyName" HeaderText="Counterparty" HeaderStyle-Width="180px"
                            FilterControlWidth="40px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="buysell" HeaderText="Buy/Sell" HeaderStyle-Width="40px"
                            FilterControlWidth="40px">
                            <FilterTemplate>
                                <telerik:RadComboBox ID="ImportedFilter" runat="server" OnClientSelectedIndexChanged="ImportedFilterSelectedIndexChanged"
                                    SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("buysell").CurrentFilterValue %>'
                                    Width="70px">
                                    <Items>
                                        <telerik:RadComboBoxItem Text="NoFilter" Value="" />
                                        <telerik:RadComboBoxItem Text="Buy" Value="B" />
                                        <telerik:RadComboBoxItem Text="Sell" Value="S" />
                                    </Items>
                                </telerik:RadComboBox>
                                <telerik:RadScriptBlock ID="RadScriptBlock12" runat="server">
                                    <script type="text/javascript">
                                        function ImportedFilterSelectedIndexChanged(sender, args) {
                                            var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                            var filterVal = args.get_item().get_value();
                                            if (filterVal == "") {
                                                tableView.filter("buysell", filterVal, "NoFilter");
                                            }
                                            else if (filterVal == "B") {
                                                tableView.filter("buysell", "B", "EqualTo");
                                            }
                                            else if (filterVal == "S") {
                                                tableView.filter("buysell", "S", "EqualTo");
                                            }
                                        } 
                                    </script>
                                </telerik:RadScriptBlock>
                            </FilterTemplate>
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="StockName" HeaderText="Stock Name" HeaderStyle-Width="120px"
                            FilterControlWidth="40px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Quantity" Aggregate="Sum" HeaderText="Quantity"
                            FilterControlWidth="40px" HeaderStyle-Width="40px" DataFormatString="{0:###,###.####}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Price" HeaderText="Price" DataFormatString="{0:###,###.####}"
                            FilterControlWidth="40px" HeaderStyle-Width="40px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="Flat" Aggregate="Sum" HeaderText="Flat Fee" DataFormatString="{0:###,###.####}"
                            FilterControlWidth="40px" HeaderStyle-Width="40px">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PerShare" HeaderText="Fee Per Share" FilterControlWidth="50px"
                            HeaderStyle-Width="50px" DataFormatString="{0:###,###.####}">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TotalFees" Aggregate="Sum" HeaderText="Total Fees"
                            HeaderStyle-Width="100px" DataFormatString="{0:###,###.####}" AllowFiltering="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TotalConsideration" Aggregate="Sum" HeaderText="Total Consideration"
                            HeaderStyle-Width="120px" DataFormatString="{0:###,###.####}" AllowFiltering="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" ConfirmText="Are you sure you want to delete"
                            ImageUrl="~/Images/Icons/trash.gif" ConfirmDialogType="RadWindow">
                        </telerik:GridButtonColumn>
                    </Columns>
                </MasterTableView>
                <%--<MasterTableView DataSourceID="ObjectDataSource1">
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
        </MasterTableView>--%>
            </telerik:RadGrid>
            <%-- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id"
        DataSourceID="ObjectDataSource1">
        <Columns>
            <asp:BoundField DataField="TransactionDate" HeaderText="T. Date" DataFormatString="{0:d}" />
            <asp:BoundField DataField="EntityName" HeaderText="Entity" />
            <asp:BoundField DataField="counterPartyName" HeaderText="Counterparty" />
            <asp:TemplateField HeaderText="Buy/Sell" HeaderStyle-HorizontalAlign="Center">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                    <asp:Label Text='<%# BuySellString(Eval("IsBuy"))%>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ValueDate" HeaderText="ValueDate" DataFormatString="{0:d}"
                SortExpression="ValueDate" />
            <asp:BoundField DataField="StockName" HeaderText="Stock" SortExpression="Stock" />
            <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
            <asp:BoundField DataField="Price" HeaderText="Price" DataFormatString="{0:f}" />
            <asp:BoundField DataField="Flat" HeaderText="Flat" SortExpression="Flat" DataFormatString="{0:f}" />
            <asp:BoundField DataField="PerShare" HeaderText="PerShare" SortExpression="PerShare"
                DataFormatString="{0:f}" />
            <asp:BoundField DataField="TotalFees" HeaderText="TotalFees" SortExpression="TotalFees"
                DataFormatString="{0:f}" />
            <asp:BoundField DataField="TotalConsideration" HeaderText="TotalConsideration" SortExpression="TotalConsideration"
                DataFormatString="{0:f}" />
            <asp:TemplateField HeaderText="Delete" HeaderStyle-HorizontalAlign="Center">
                <ItemStyle HorizontalAlign="Center" />
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Icons/trash.gif"
                        CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete')" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>--%>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="Select"
                DeleteMethod="Delete" TypeName="TreaShares.Backoffice.Controlers.TransactionManager">
                <SelectParameters>
                    <asp:CookieParameter CookieName="OrganisationId" Name="ClientId" Type="String" />
                </SelectParameters>
                <DeleteParameters>
                    <asp:Parameter Name="id" Type="Int32" />
                </DeleteParameters>
            </asp:ObjectDataSource>
        </div>
        <div id="tabs-2">
            <table border="0" cellpadding="2" cellspacing="2">
                <tr>
                    <td>
                        From
                    </td>
                    <td>
                        <asp:TextBox ID="txtSummaryFrom" runat="server" ClientIDMode="Static"></asp:TextBox>
                    </td>
                    <td>
                        To
                    </td>
                    <td>
                        <asp:TextBox ID="txtSummaryTo" runat="server" ClientIDMode="Static"></asp:TextBox>
                    </td>
                    <td align="right">
                        <asp:Button ID="btnTransactionSummary" runat="server" Text="Run" CssClass="button"
                            OnClick="btnTransactionSummary_Click" />
                    </td>
                </tr>
            </table>
            <telerik:RadGrid ID="rgTransactionSummary" runat="server" AutoGenerateColumns="false">
                <MasterTableView Width="100%" Summary="RadGrid table" HeaderStyle-HorizontalAlign="Center">
                    <Columns>
                        <telerik:GridBoundColumn DataField="Stock" HeaderText="Stock" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="Sharesrepurchased" HeaderText="Shares Repurchased"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridBoundColumn DataField="Currency" HeaderText="Currency" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="WeightedAverageCost" HeaderText="Weighted Average Cost"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="WeightedAverageTotalCost" HeaderText="Weighted Average Total Cost"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="TotalCost" HeaderText="Total Cost" HeaderStyle-Width="50px"
                            DataFormatString="{0:###,###.##}" />
                        <telerik:GridNumericColumn DataField="PaidUpCapital" HeaderText="Paid Up Capital"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="weightedPaidUpCapital" HeaderText="Weighted Average Paid Up Capital"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="WeightedAverageTreasuryStock" HeaderText="Weighted Average Treasury Stock"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="WeightedAverageSharesOutstanding" HeaderText="Weighted Average Shares Outstanding"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="GrossBurnRate" HeaderText="Industry Burn Rate (%)"
                            DataFormatString="{0:###,###.##}" HeaderStyle-Width="50px" />
                        <telerik:GridNumericColumn DataField="NetBurnRate" HeaderText="Net Burn Rate (%)"
                            HeaderStyle-Width="50px" DataFormatString="{0:###,###.##}" />
                        <telerik:GridNumericColumn DataField="Overhang" HeaderText="Overhang (%)" HeaderStyle-Width="50px" />
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
        </div>
    </div>
</asp:Content>
